﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    public class BinaryTreeNode
    {
        public int value;
        public BinaryTreeNode left;
        public BinaryTreeNode right;

        public BinaryTreeNode(int value)
        {
            this.value = value;
        }

        public BinaryTreeNode(int value, BinaryTreeNode left, BinaryTreeNode right)
        {
            this.value = value;
            this.left = left;
            this.right = right;
        }
    }
    /// <summary>
    /// 二叉树 三种遍历
    /// 前，中，后
    /// </summary>
    class BinaryTree
    {
        /// <summary>
        /// 前
        /// </summary>
        public void DLR(BinaryTreeNode root)
        {
            Console.Write(root.value + "  ");

            if (root.left != null)
            {
                DLR(root.left);
            }

            if (root.right != null)
            {
                DLR(root.right);
            }
        }
        /// <summary>
        /// 中
        /// </summary>
        public void LDR(BinaryTreeNode root)
        {
           
            if (root.left != null)
            {
                LDR(root.left);
            }

            Console.Write(root.value + "  ");

            if (root.right != null)
            {
                LDR(root.right);
            }
        }
        /// <summary>
        /// 后
        /// </summary>
        public void LRD(BinaryTreeNode root)
        {
            
            if (root.left != null)
            {
                LRD(root.left);
            }

            if (root.right != null)
            {
                LRD(root.right);
            }
            Console.Write(root.value + "  ");
        }
    }
}
